﻿Public Class CLSProdutos

#Region "Atributos"
    Dim sql As String
    Dim objbanco As New CLSBanco
    Dim M_Pro_ID As Integer
    Dim M_Pro_Nom As String
    Dim M_Pro_Uni As Integer
    Dim M_Pro_VU As Single
    Dim M_Pro_VT As Single
    Dim M_Pro_Qtd As Integer

#End Region
#Region "Gets e Seteres"

    Public Property ID() As Integer
        Get
            Return M_Pro_ID
        End Get
        Set(ByVal value As Integer)
            M_Pro_ID = value
        End Set
    End Property

    Public Property NomeProduto() As String
        Get
            Return M_Pro_Nom
        End Get
        Set(ByVal value As String)
            M_Pro_Nom = value
        End Set
    End Property

    Public Property Unidade() As Integer
        Get
            Return M_Pro_Uni
        End Get
        Set(ByVal value As Integer)
            M_Pro_Uni = value
        End Set
    End Property

    Public Property valorUnitario() As Double
        Get
            Return M_Pro_VU
        End Get
        Set(ByVal value As Double)
            M_Pro_VU = value
        End Set
    End Property
    Public Property ValorTotal() As Double
        Get
            Return M_Pro_VT
        End Get
        Set(ByVal value As Double)
            M_Pro_VT = value
        End Set
    End Property
    Public Property Quantidade() As Integer
        Get
            Return M_Pro_Qtd
        End Get
        Set(ByVal value As Integer)
            M_Pro_Qtd = value
        End Set
    End Property

#End Region
#Region "Método Gravar"

    Public Sub Gravar(ByVal novo As Boolean)
        If novo Then
            sql = "insert into Produto " & _
            "(Pro_ID" & _
              ",Pro_Nom" & _
              ",Pro_Uni" & _
              ",Pro_VU" & _
              ") values " & _
              "(" & M_Pro_ID & _
              ",'" & M_Pro_Nom & "'" & _
              "," & M_Pro_Uni & _
              ",'" & M_Pro_VU & "'" & _
              ")"
            objbanco.executar_comando(sql)
        Else
            sql = "update Produto set" & _
            " Pro_Nom= '" & M_Pro_Nom & "'" & _
            ",Pro_Uni= " & M_Pro_Uni & _
            ",Pro_VU= '" & M_Pro_VU & "'" & _
            " where Pro_ID= " & M_Pro_ID
            objbanco.executar_comando(sql)
        End If


    End Sub
#End Region
#Region "Método Excluir"

    Public Function excluir(ByVal meucliente As Integer) As Boolean
        sql = "delete from Produto where Pro_ID=" & meucliente
        objbanco.executar_comando(sql)
        Return True
    End Function

#End Region
#Region "Método Localizar por Código"
    Public Function LocalizarPorID(ByVal digiteID As Integer) As DataTable
        sql = "select * from Produto where Pro_ID = " & digiteID
        Dim objda As New OleDb.OleDbDataAdapter(sql, objbanco.objcon)
        Dim objds As New DataSet
        objda.Fill(objds)
        Return objds.Tables(0)
    End Function
#End Region

End Class
